package com.cooper.scraper.show;

import java.util.List;

import com.cooper.android.comm.Resource;

import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.view.Display;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;

public abstract class FanartsShow<T extends Resource> {

	protected Context context;
	protected FanartViewStrategy<T> fanartStrategy;
	protected ResourceShowListener<T> showListener;

	public FanartsShow(Context context, FanartViewStrategy<T> fanartStrategy) {
		super();
		this.context = context.getApplicationContext();
		this.fanartStrategy = fanartStrategy;
	}
	
	protected void init(){
		fanartStrategy.init(context, getFanartImgStrategy(),
				getFanartShowCount());		
	}

	public abstract int getFanartShowCount();

	public abstract void setCommands(List<ResourceCommandAction<T>> commands);

	protected abstract FanartImgStrategy getFanartImgStrategy();

	protected abstract AdapterView<?> getAdapterView();

	public void configurationChanged(Configuration configuration,
			Display display) {
		fanartStrategy.configurationChanged(configuration, display,
				getFanartShowCount());
	}

	public void setMediasShowListener(ResourceShowListener<T> showListener) {
		this.showListener = showListener;
	}

	public void setAdapter(FanartAdapter<T> fanartAdapter) {
		fanartAdapter.setFanartsShow(this);
		fanartAdapter.refresh();
	}

	public void registerContextMenu(Activity activity) {
		activity.registerForContextMenu(getAdapterView());
	}

	@SuppressWarnings("unchecked")
	public T getSelectedResource() {
		return (T) getAdapterView().getSelectedItem();
	}

	public void destroy() {
		getAdapterView().setAdapter(null);
		fanartStrategy.destroy();
	}

	public abstract void removeFrom(ViewGroup from);

	public abstract void showTo(ViewGroup to);

	public abstract void setSelection(int position, boolean animate);

	public abstract void hideOrShowFanartsView();

	public abstract void resetSelected();

	public void resetFanart() {
		fanartStrategy.reset();
	}

	public abstract View getResourceView(T media, View convertView,
			ViewGroup parent);

	public abstract int dataAddDirection();

}
